package com.xiaoyu.tool.controller.admin.user;


import com.xiaoyu.tool.service.user.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * 管理员用户操作
 * */
@Controller
@RequestMapping("/admin/users")
public class AdminUserController {

    private final UserService userService;

    public AdminUserController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping
    public String index(Model model) {
        model.addAttribute("users", userService.findAll());
        return "admin/user/index";
    }

    /**
     * 添加粉丝
     * */
    @PatchMapping("/change/{userId}")
    public String addFansCount(@PathVariable Long userId, @RequestParam(name = "fansCount") Integer fansCount){
        userService.addFansCount(userId,fansCount);
        return "redirect:/admin/users";
    }

    /**
     * 取消合伙人资格
     * */
    @GetMapping("/recusal/{userId}")
    public String recusalAgent(@PathVariable Long userId){
        userService.recusalAgent(userId);
        return "redirect:/admin/users";
    }
}
